<?php
include_once("./function.php");
$sql="select * from ts_user";
if(isset($_GET['sub']))
{
	extract($_GET);//$admin
	$sql="select * from ts_user where admin='$admin'";
}

$res=mysqli_query($link,$sql);
if(is_object($res))
{
		$total=mysqli_num_rows($res);
		$num=4;
		$page=1;
		$pages=ceil($total/$num);
        if(isset($_GET['page']))
		{
			$page=$_GET['page'];
		}
		$start=($page-1)*$num;
		$sql.=" order by uid desc limit $start,$num";	
		
}
		$res=mysqli_query($link,$sql);
		if(is_object($res))
		{
			if(mysqli_num_rows($res)>0)
			{
				$sys=array();
				while(($list=mysqli_fetch_assoc($res))!=false)
				{
					$sys[]=$list;
				}
			}
		}
	//print_r($sys);	
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主体部分</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<form action="admin_user.php" method="get" align="center">
<?php include_once("./function.php");?>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="./skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' border="0px"><span><img src='./skin/images/frame/arr3.gif' style='margin-right:10px;'>用户管理</span></td>
	<td align="right" background="./skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' border="0px"></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td colspan="2">
		<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CFCFCF" align="center" style="margin-top:8px">
		<tr align="center" bgcolor="#FBFCE2" height="25">
			<td colspan=8>
				用户类型:<input type="radio" name="admin" value="1" checked/>管理员
						<input type="radio" name="admin" value="0" <?php if(isset($admin)&&$admin=='0'){echo 'checked';}?>/>普通用户
							<input type="submit" name="sub" />
			</td>
		</tr>
			<tr align="center" bgcolor="#FBFCE2" height="25">
				<td width="6%">ID</td>
				<td>用户名</td>
				<td width="20%">手机号</td>
				<td width="15%">邮箱</td>
				<td width="15%">启用/禁用</td>
				<td width="15%">管理员</td>
			</tr>
  <!-- data start-->
		<?php 
			if(isset($sys)){foreach($sys as $v){
		?>
			<tr align='center' bgcolor="#FFFFFF" height="26" align="center" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
				<td nowrap><?=$v['uid']?></td>
				<td><?=$v['username']?></td>
				<td><?=$v['mobile']?></td>
				<td><?=$v['email']?></td>
				<td>
					<a href="do_admin_user.php?ifshow=<?=$v['ifshow']?>&uid=<?=$v['uid']?>">
						<font color="blue">
						<?php if($v['ifshow']=="0"){?>
						<?php echo "<b>禁用</b>";}elseif($v['ifshow']=="1"){?>
						<?php echo "启用";}?></font>
					</a>
				</td>
				<td>
					<a href="do_admin_user.php?admin=<?=$v['admin']?>&uid=<?=$v['uid']?>">
						<font color="blue">
						<?php if($v['admin']=="0"){?>
						<?php echo "<b>普通用户</b>";}elseif($v['admin']=="1"){?>
						<?php echo "管理员";}?></font>
					</a>
				</td>
			</tr>
			<?php }}?>
				</table>
			</td>
		  </tr>
  <!-- data end-->
 
  <!-- page start-->
	  <tr align="right" bgcolor="#F9FCEF">
			<!--第<?=isset($page)?$page:1?>页/共<?php if($pages==0){?><?php echo 1;}else{echo $pages;}?>页-->
		<td colspan=8 align="center">
			<?php if(isset($_GET['sub'])){if(isset($page)&&$page>1){?>
			<a href="admin_user.php?page=<?=$page-1?>&admin=<?=$_GET['admin']?>&sub=<?=$_GET['sub']?>">上一页</a>
			<?php }?>

			<a>第<?=isset($page)?$page:1?>页/共<?=isset($pages)?$pages:1?>页</a>

			<?php if(isset($page)&&$page<$pages){?>

			<a href="admin_user.php?page=<?=$page+1?>&admin=<?=$_GET['admin']?>&sub=<?=$_GET['sub']?>">下一页</a>

			<?php }}
			else{if(isset($page)&&$page>1){?>
			<a href="admin_user.php?page=<?=$page-1?>">上一页</a>
			<?php } ?>
			
			第<?=isset($page)?$page:1?>页/共<?=isset($pages)?$pages:1?>页
			<?php if(isset($page)&&$page<$pages){?><a href="admin_user.php?page=<?=$page+1?>">下一页</a>
		<?php }}?>
		</td>
	  </tr>
  <!-- page end-->
 
</table>
</form>
</body>
</html>
